import java.util.ArrayList;
import java.util.Comparator;

public class list3 {
    public static void main(String[] args) {
        ArrayList<student> list = new ArrayList<>();
        student stu1 = new student("张三", 19, "男");
        student stu2 = new student("李四", 14, "男");
        student stu3 = new student("王五", 12, "男");
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.sort(new Comparator<student>() {
            @Override
            public int compare(student o1, student o2) {
                int result = o1.getAge() - o2.getAge();
                return result;
            }
        });
        list.get(list.size() - 1).setName("小猪佩奇");
        list.forEach(student -> System.out.println(student.toString()));
    }
}
